package listbyorder.access201_300.test202;

import java.util.HashSet;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/18 11:28
 */
public class Solution2 {

    public boolean isHappy(int n) {
        if (n == 1) return true;
        HashSet<Integer> set = new HashSet<>();
        while (n != 1) {
            int next = 0;
            while (n > 0) {
                int t = n % 10;
                next += t * t;
                n /= 10;
            }
            if (set.contains(next)) {
                return false;
            }
            set.add(next);
            n = next;
        }
        return true;
    }
}
